from parse_csv import ParseCsv
from datetime import datetime

class Highs:
    """获取温度类"""

    def __init__(self, filename) -> None:
        
        self.filename = filename
        self.parse_csv = ParseCsv(f'csv_sif/file/{self.filename}')

    def get_tmax(self) -> tuple[list, list]:
        """获取最高气温"""

        dates, highs = [], []
        for data in self.parse_csv.query_columns(["DATE", "TMAX"]):
            date = datetime.strptime(data['DATE'], '%Y-%m-%d')
            try:
                high = int(data["TMAX"])
            except ValueError:
                print(f"日期:{date} 未查询到最高气温")
            else:
                dates.append(date)
                highs.append(high)
        return dates, highs
    
    def get_tmax_and_tmin(self) -> tuple[list, list, list]:
        """获取最高气温以及最低气温"""

        dates, highs, lows = [], [], []
        for data in self.parse_csv.query_columns(["DATE", "TMAX", "TMIN"]):
            date = datetime.strptime(data['DATE'], '%Y-%m-%d')
            try:
                high = int(data["TMAX"])
                low = int(data["TMIN"])
            except ValueError:
                print(f"日期:{date} 未查询到最高气温或者最低气温")
            else:
                dates.append(date)
                highs.append(high)
                lows.append(low)
        return dates, highs, lows
